﻿using System;
using System.Collections.Generic;
using System.Linq;
using AppModule.InterProcessComm;
using AppModule.NamedPipes;
using System.IO;

namespace SendCommand
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            IInterProcessConnection clientConnection = null;
            string sendCommand = AppDomain.CurrentDomain.BaseDirectory + "~SendCommand.tmp";

            try
            {
                clientConnection = new ClientPipeConnection("WinCommandPipe", ".");
                clientConnection.Connect();
            
                StreamReader sr = File.OpenText(sendCommand);
                string command = sr.ReadToEnd();
                sr.Close();

                clientConnection.Write(command);
                clientConnection.Close();
            }
            catch (Exception ex)
            {
                //throw (ex);
            }
            finally {
                clientConnection.Dispose();
                File.Delete(sendCommand);
            }
        }
    }
}
